package com.tledu.course.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.tledu.course.domain.SectionManagement;
import com.tledu.course.service.ISectionManagementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 章节管理Controller
 * 
 * @author Ghost
 * @date 2021-07-13
 */
@Controller
@RequestMapping("/course/management")
public class SectionManagementController extends BaseController
{
    private String prefix = "course/management";

    @Autowired
    private ISectionManagementService sectionManagementService;

    @RequiresPermissions("course:management:view")
    @GetMapping()
    public String management()
    {
        return prefix + "/management";
    }

    /**
     * 查询章节管理列表
     */
    @RequiresPermissions("course:management:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SectionManagement sectionManagement)
    {
        startPage();
        List<SectionManagement> list = sectionManagementService.selectSectionManagementList(sectionManagement);
        return getDataTable(list);
    }

    /**
     * 导出章节管理列表
     */
    @RequiresPermissions("course:management:export")
    @Log(title = "章节管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SectionManagement sectionManagement)
    {
        List<SectionManagement> list = sectionManagementService.selectSectionManagementList(sectionManagement);
        ExcelUtil<SectionManagement> util = new ExcelUtil<SectionManagement>(SectionManagement.class);
        return util.exportExcel(list, "章节管理数据");
    }

    /**
     * 新增章节管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存章节管理
     */
    @RequiresPermissions("course:management:add")
    @Log(title = "章节管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SectionManagement sectionManagement)
    {
        return toAjax(sectionManagementService.insertSectionManagement(sectionManagement));
    }

    /**
     * 修改章节管理
     */
    @GetMapping("/edit/{sectionId}")
    public String edit(@PathVariable("sectionId") Integer sectionId, ModelMap mmap)
    {
        SectionManagement sectionManagement = sectionManagementService.selectSectionManagementById(sectionId);
        mmap.put("sectionManagement", sectionManagement);
        return prefix + "/edit";
    }

    /**
     * 修改保存章节管理
     */
    @RequiresPermissions("course:management:edit")
    @Log(title = "章节管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SectionManagement sectionManagement)
    {
        return toAjax(sectionManagementService.updateSectionManagement(sectionManagement));
    }

    /**
     * 删除章节管理
     */
    @RequiresPermissions("course:management:remove")
    @Log(title = "章节管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sectionManagementService.deleteSectionManagementByIds(ids));
    }
}
